package com.dreamsail.core.model.system;

import io.swagger.models.auth.In;
import lombok.Data;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.util.List;

/**
 * 分页请求内容
 */
@Data
public class PageReq<T> implements Pageable {

    /**
     * 一页大小
     */
    private Integer pageSize;

    /**
     * 页码（从1开始，如果是0，则设置为1）
     */
    private Integer pageNo;

    /**
     * 开始数据位置
     */
    private Integer offset;

    /**
     * 查询条件
     */
    private T queryParam;


    private List<QueryOrder> queryOrderList;


    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
        if(pageNo != null){
            if(pageNo == 0){
                offset = 0;
            }else{
                offset = (pageNo - 1) * pageSize;
            }
        }
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
        if(pageSize != null){
            if(pageNo == 0){
                offset = 0;
            }else{
                offset = (pageNo - 1) * pageSize;
            }
        }
    }

    @Override
    public int getPageNumber() {
        return pageNo;
    }

    @Override
    public long getOffset() {
        return 0;
    }

    @Override
    public Sort getSort() {
        return null;
    }

    @Override
    public Pageable next() {
        return null;
    }

    @Override
    public Pageable previousOrFirst() {
        return null;
    }

    @Override
    public Pageable first() {
        return null;
    }

    @Override
    public Pageable withPage(int pageNumber) {
        return null;
    }

    @Override
    public boolean hasPrevious() {
        return false;
    }
}
